package cn.antblog.sort;

/**
 * description: InsertSort 插入排序
 * date: 2020/9/29 10:58 <br>
 * author: YangJy <br>
 */
public class InsertSort {
    public static void main(String[] args) {
        insertSort();
    }

    private static void insertSort() {
        int num[] =  {5,23,86,21,43,67,45,34,58,23,102,123,11,22,1};
        int pos , curr;
        //pos //有序队列的最后一个元素指针
        //curr，待排序的元素
        for(int i = 1;i<num.length;i++){
            pos = i-1;
            curr = num[i];
            while (pos>=0 && num[pos]>curr){
                num[pos+1] = num[pos];
                pos--;
            }
            num[pos+1] = curr;
        }
        for (int i : num){
            System.out.print(i+"|");
        }
    }


}
